package main;

import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Properties;

import framework.system.BackEnd;
import framework.system.BackEndImpl;
import framework.system.FrontEnd;
import framework.system.FrontEndImpl;


//TODO TreeView and GridView created every time peers changes in BackEnd
//TODO add tasks that can be pushed to a mediator

public class Server {

	public static void main(String[] args) {
		try {
			//the commented block will be needed when testing the whole thing with mor than one computers
			
			Properties systemProperties = 
			      new Properties( System.getProperties() );
			//SERVER IP eintragen anstatt von localhost
			systemProperties.put("java.rmi.server.hostname","localhost");
			systemProperties.put("java.security.policy", "policy");
			System.setProperties(systemProperties);
			if(System.getSecurityManager() == null){
				System.setSecurityManager(new RMISecurityManager());
			}
			
			
			String port = Integer.toString(Registry.REGISTRY_PORT);
			Registry registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
			
			BackEndImpl backEnd = new BackEndImpl();
			registry.rebind(
					"rmi://localhost:" + port + "/" + BackEnd.SERVICENAME,
					backEnd);
			FrontEndImpl frontEnd = new FrontEndImpl(backEnd);
			registry.rebind(
					"rmi://localhost:" + port + "/" + FrontEnd.SERVICENAME,
					frontEnd);
			

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
